package com.junchenrobot.mes.controller;

import com.junchenrobot.mes.response.BaseResponse;
import com.junchenrobot.mes.service.RcsService;
import com.junchenrobot.mes.vo.param.GateResourceParam;
import com.junchenrobot.mes.vo.param.TaskStateParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * wcs控制器
 *
 * @author SeaWave
 * @date 2022/11/14
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/mes", produces = "application/json;charset=UTF-8")
public class RcsController {
    
    
    /**
     * rcs服务
     */
    private final RcsService rcsService;
    
    @Autowired
    public RcsController(RcsService rcsService) {
        this.rcsService = rcsService;
    }
    
    /**
     * 上报任务状态
     *
     * @param taskStateParam 任务状态参数
     * @return {@link BaseResponse}
     */
    @PostMapping("/taskStatus")
    public BaseResponse taskState(@RequestBody TaskStateParam taskStateParam) {
        System.out.println(taskStateParam);
        System.out.println("taskno:"+taskStateParam.getTaskNo());
        System.out.println("state"+taskStateParam.getState());
        System.out.println("+=======");

        return rcsService.taskStatus(taskStateParam);
    }
    
    /**
     * 打开门
     *
     * @param gateResourceParam 大门资源参数
     * @return {@link BaseResponse}
     */
    @PostMapping("/openDoor")
    public BaseResponse openDoor(@RequestBody GateResourceParam gateResourceParam) {
        log.info("打开门{}", gateResourceParam);
        gateResourceParam.setAction(1);
        return rcsService.updateGateStatus(gateResourceParam);
    }
    
    
    /**
     * 关闭门
     *
     * @param gateResourceParam 大门资源参数
     * @return {@link BaseResponse}
     */
    @PostMapping("/closeDoor")
    public BaseResponse closeDoor(@RequestBody GateResourceParam gateResourceParam) {
        log.info("关闭门{}", gateResourceParam);
        gateResourceParam.setAction(0);
        return rcsService.updateGateStatus(gateResourceParam);
    }
    
}